package demo1;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.time.Duration;

public class JedisConnectionFactory {
    private static final JedisPool jedispool;
    static {
        //配置连接池
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(8);//设置最大连接数
        config.setMaxIdle(8);//设置最大空闲连接数
        config.setMinIdle(0);//设置最小空闲连接数
        config.setMaxWait(Duration.ofSeconds(10));//设置最大等待时间10秒
        //创建连接池对象
        jedispool = new JedisPool(config,"localhost",6379,1000,"123456");
    }
    public static Jedis getJedis(){
        return jedispool.getResource();
    }
}
